package com.chinairi.mall.controller;


import com.chinairi.common.utils.ResponseUtil;
import com.chinairi.mall.controller.viewobject.*;
import com.chinairi.mall.model.OrderServiceTransport;
import com.chinairi.mall.service.IProjectPlanPickingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.chinairi.common.controller.BaseController;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 领料单 前端控制器
 * </p>
 *
 * @author Webgasd
 * @since 2020-10-13
 */
@RestController
@RequestMapping("/project-plan-picking")
public class ProjectPlanPickingController extends BaseController {
    @Autowired
    private IProjectPlanPickingService projectPlanPickingService;

    /**
     * 存储
     * @param projectPlanPickingVo
     * @throws IOException
     */
    @PostMapping("/add")
    public void addProject(@RequestBody ProjectPlanPickingVO projectPlanPickingVo) throws IOException {
        projectPlanPickingService.add(projectPlanPickingVo);
        ResponseUtil.showMessage("success", "创建领料单成功", "");
    }

    /**
     * 筛选回传的物料list
     * @param projectPlanReqVO
     * @throws IOException
     */
    @PostMapping("/getCanPickList")
    public void getCanPickList(@RequestBody ProjectPlanReqVO projectPlanReqVO) throws IOException {
        ProjectPlanPickingVO projectPlanPickingVo = projectPlanPickingService.getCanPickList(projectPlanReqVO);
        ResponseUtil.showMessage("success", "筛选物料列表成功", projectPlanPickingVo);
    }

    /**
     * 获取list列表
     * @throws IOException
     */
    @GetMapping("/getList")
    public void getList() throws IOException {
        ResponseUtil.showMessage("success", "获取领料单成功", projectPlanPickingService.getList());
    }

    /**
     * 获取领料单详情
     * @param pickId
     * @throws IOException
     */
    @GetMapping("/getOneByPickId")
    public void getOneByPickId(String pickId) throws IOException {
        ProjectPlanPickingOrderVO projectPlanPickingOrderVO = projectPlanPickingService.getOneByPickId(pickId);
        ResponseUtil.showMessage("success", "获取领料单成功", projectPlanPickingOrderVO);
    }

    /**
     * 获取领料单服务单列表
     * @param pickId
     * @throws IOException
     */
    @GetMapping("/getOrderServiceTransportList")
    public void getOrderServiceTransportList(String pickId) throws IOException {
        List<OrderServiceTransport> orderServiceTransportList = projectPlanPickingService.getOrderServiceTransportList(pickId);
        ResponseUtil.showMessage("success", "获取领料单服务单列表成功", orderServiceTransportList);
    }

    /**
     * 获取领料单服务单详情
     * @param ostId
     * @throws IOException
     */
    @GetMapping("/getOrderServiceInfo")
    public void getOrderServiceInfo(String ostId) throws IOException {
        OrderServiceTransportVO orderServiceTransportVo = projectPlanPickingService.getOrderServiceInfo(ostId);
        ResponseUtil.showMessage("success", "获取领料单服务单详情成功", orderServiceTransportVo);
    }

    /**
     * 选服务，回传服务信息
     * @param projectPlanPickingOrderVo
     * @throws IOException
     */
    @PostMapping("/getServiceInfo")
    public void getServiceInfo(@RequestBody ProjectPlanPickingOrderVO projectPlanPickingOrderVo) throws IOException {
        ProjectPlanPickingOrderVO projectPlanPickingOrderVoResult = projectPlanPickingService.getServiceInfo(projectPlanPickingOrderVo);
        ResponseUtil.showMessage("success", "获取服务详情成功", projectPlanPickingOrderVoResult);
    }

    /**
     * 重选服务
     * @param projectPlanPickingOrderVo
     * @throws IOException
     */
    @PostMapping("/updateServiceOfPickOrder")
    public void updateServiceOfPickOrder(@RequestBody ProjectPlanPickingOrderVO projectPlanPickingOrderVo) throws IOException {
        ProjectPlanPickingOrderVO projectPlanPickingOrderVoResult = projectPlanPickingService.updateServiceOfPickOrder(projectPlanPickingOrderVo);
        ResponseUtil.showMessage("success", "重选成功", projectPlanPickingOrderVoResult);
    }

    /**
     * 删除领料单服务单
     * @param beforeOrderId
     * @throws IOException
     */
    @GetMapping("/deleteServiceOrder")
    public void deleteServiceOrder(String beforeOrderId) throws IOException {
        projectPlanPickingService.deleteServiceOrder(beforeOrderId);
        ResponseUtil.showMessage("success", "撤销领料单服务单成功", "");
    }

    /**
     * 插入服务。
     * @param projectPlanPickingOrderVo
     * @throws IOException
     */
    @PostMapping("/addPickOrder")
    public void addPickOrder(@RequestBody ProjectPlanPickingOrderVO projectPlanPickingOrderVo) throws IOException {
        projectPlanPickingService.addPickOrder(projectPlanPickingOrderVo);
        ResponseUtil.showMessage("success", "提交服务单成功", "");
    }
}
